<template>
	<view>
		<view style="padding: 10px">分享客户：</view>
		<uni-list-item v-for="(item, index) in shareCustomer" :key="index">
			<!-- 自定义 header -->
			<template v-slot:header>
				<view style="flex: 1; display: flex; align-items: center">
					<image style="width: 40px; height: 40px; border-radius: 20px"
						:src="item.ciAvat? item.ciAvat: tempImageUrl" mode="widthFix">
					</image>
					<view style="margin-left: 8px; font-size: 13px">
						<view>{{ (item.ciName || '') + (item.ciAlia ? '(' + item.ciAlia + ')' : '') }}</view>
						<view>{{ (item.ciPhon || '') }}</view>
					</view>
				</view>
			</template>
			<!-- 自定义 footer-->
			<template v-slot:footer>
				<view style="margin-top: 5px;">{{UTCTimeToLocal(item.clTime)}}</view>
			</template>
		</uni-list-item>

		<view style="padding: 30px 10px 0px 10px;">所属员工：</view>
		<uni-list-item v-for="(item, index) in beloneStaff" :key="index">
			<!-- 自定义 header -->
			<template v-slot:header>
				<view style="display: flex; align-items: center">
					<view>{{ (item.orName || '')}}</view>
					<view>{{ '-'+ (item.orPhon || '') }}</view>
				</view>
			</template>
			<!-- 自定义 footer-->
			<template v-slot:footer>
				<view style="margin-top: 5px;">{{UTCTimeToLocal(item.clTime)}}</view>
			</template>
		</uni-list-item>
	</view>
</template>

<script>
	import {
		getCustomerRelationship,
		getCustomerByCiUuid,
		getStaffByOrUuid
	} from "../../utils/api.js"
	export default {
		data() {
			return {
				shareCustomer: [],
				beloneStaff: [],
				tempImageUrl: "http://jdc.jd.com/img/100x100/",
			}
		},
		onLoad(params) {
			if (params.ciUuid) {
				this.getCustomerRelationship(params.ciUuid)
			}
		},
		methods: {
			async getCustomerRelationship(ciUuid) {
				let res = await getCustomerRelationship(ciUuid);
				if (res) {
					res.forEach(async item => {
						if (item.scUuid !== "00000000-0000-0000-0000-000000000000") {
							// shareCustomer.push(item.scUuid)
							let resCust = await getCustomerByCiUuid(item.scUuid);
							if (resCust.ciUuid) {
								let custObj = {
									...resCust,
									clTime: item.clTime
								}
								this.shareCustomer.push(custObj)
							}
						}
						if (item.orUuid !== "00000000-0000-0000-0000-000000000000") {
							// beloneStaff.push(item.orUuid)
							let resstaff = await getStaffByOrUuid(item.orUuid);
							if (resstaff.orUuid) {
								let staffObj = {
									...resstaff,
									clTime: item.clTime
								}
								this.beloneStaff.push(staffObj)
							}
						}
					})
				}
			}
		}
	}
</script>

<style>
</style>
